package jfinal.demo.company;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import jfinal.demo.common.model.Company;

public class CompanyService {
    /**
     * 所有的 dao 对象也放在 Service 中
     */
    private static final Company dao = new Company().dao();

    public Page<Company> paginate(int pageNumber, int pageSize) {
        return dao.paginate(pageNumber, pageSize, "select a.id id , a.cname, a.cdress, a.createtime, b.username  ", "from company a \n" +
                "LEFT JOIN `user` b on a.creater = b.id ORDER BY a.id desc");
    }

    public Company findById(int id){
        return dao.findById(id);
    }

    public boolean add(Controller controller){
        Company company =  controller.getModel(Company.class);
        company.setCreater(controller.getCookieToInt("userid"));
        return company.save();
    }

    public boolean delete(Controller controller){
         return  dao.findById(controller.getParaToInt()).delete();
    }

    public boolean updata(Controller controller){
       return controller.getModel(Company.class).update();
    }

}
